a5a24db34233df15a8e128a9636cec4eaabcdbad,src/edu/stanford/nlp/util/concurrent/ConcurrentHashIndex.java,ConcurrentHashIndex,indexOf,#E#boolean#,68
Before Change
// non-negative and continuous. We tried to satisfy this requirement without
// a lock (e.g., by using AtomicInteger) but couldn't make it work.
synchronized(this) {
if ( ! item2Index.containsKey(o)) {
int newIndex = index2Item.size();
item2Index.put(o, newIndex);
index2Item.put(newIndex, o);
}
}
return item2Index.get(o);
After Change
@Override
public int indexOf(E o, boolean add) {
Integer atomic = item2Index.get(o);
if (atomic == null) {
if (add) {
final int newIndex = indexCounter.getAndIncrement();
atomic = item2Index.putIfAbsent(o, newIndex);
if (atomic == null) {
index2Item.put(newIndex, o);
return newIndex;
} else {
return item2Index.get(o);